<template>
  <div class="app-container">
    <div class="common-content contact">
      <!--        编辑模式-->
      <div class="edit">
        <div class="title">
          编辑模式
        </div>
        <div class="edit-content">
          <el-input
            type="textarea"
            :placeholder="placeholder"
            v-model="editContent"
            :maxlength="maxlength"
            show-word-limit
            clearable
            autosize
            @input="inputHandle"
          >
          </el-input>
          <div class="submit">
            <el-button type="primary" @click="submit">保存</el-button>
          </div>
        </div>
      </div>
      <!--        预览模式-->
      <div class="preview">
        <div class="title">
          预览模式
        </div>
        <div class="detail">
          <div class="list" v-for="(item ,index) in contentList" :key="index">
            {{item}}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'BloggerEdit',
    props:{
      url:{
        type:String,
        default:''
      }
    },
    data() {
      return {
        editContent: '',//编辑内容
        contentList:[],//预览内容
        placeholder:"每一行通过回车分割...",
        maxlength:300,//限制字数长度
      }
    },
    mounted(){

    },
    methods:{
      //  输入值发生改变
      inputHandle(){
        let textArr = this.editContent.split(/[(\r\n)\r\n]+/)
        let contentArr = []
        textArr.map(item=>{
          contentArr.push(item.replace(/\s*/g,""))
        })
        this.contentList = contentArr
      },
      //  保存
      submit(){
        if(this.editContent.trim()==''){
          this.$message.error('输入内容不能为空...')
          console.log('submit')
          return
        }
      }
    }
  }
</script>

<style scoped lang="scss">
  .app-container {
    .contact {
      display: flex;
      justify-content: space-between;
      /*编辑*/
      .title {
        text-align: center;
        margin-bottom: 20px;
        font-size: 18px;
      }

      .edit {
        width: 46%;
        height: 100%;
      }

      /*  预览*/
      .preview {
        width: 46%;
        height: 100%;
        .detail{
          border: 1px solid #20a0ff;
          border-radius: 5px;
          .list{
            text-align: center;
            font-size: 15px;
            line-height: 28px;
            color: #606266;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
      }
    }
  }
</style>
